<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //1.boolean转化为数字类型时，true为1，false为0
    var b1 = true;
    var b2 = false;
    var result1 = b1 + 0;
    var result2 = b2 + 0;
    console.log(result1,result2)//1 0

    //2.undefined转化为数字，结果为NaN
    //3.null转化为数字，结果为0
    var n1 = null;
    var result4 = Number(null);
    console.log(result4);

    //4.可以使用parseInt、parseFloat、Number来实现将
    //字符串转化为数字类型，如果字符串是一个非纯数字字符
    //的字符串，转化结果就是NaN
    var str1 = "123";
    var str2 = "abc123";
    var result5 = parseInt(str1);
    console.log(result5);
    var result6 = parseInt(str2);
    console.log(result6);//NaN
</script>
</html>